//
//  UIImageView+WebImage.swift
//  仿写微博
//
//  Created by Apple on 17/7/25.
//  Copyright © 2017年 tuimao. All rights reserved.
//
//SD网络imageView的封装
import SDWebImage

extension UIImageView{
    
    /// SD网络imageView的封装
    ///
    /// - Parameters:
    ///   - urlString: 图片的url字符串
    ///   - placeholderImage: 占位图
    func cz_setImage(urlString:String?,placeholderImage:UIImage?,isAvatar:Bool){
        guard let urlString = urlString,let url = URL(string: urlString)else{
            image = placeholderImage
            return
        }
        //placeholderImage 可以传入可选 这是oc方法
        sd_setImage(with: url, placeholderImage: placeholderImage, options: [], progress: nil) { [weak self](image, _, _, _) in
            //完成回调-是否是图像
            if isAvatar{
                self?.image = image?.cz_avatarImage(size: self?.bounds.size)
            }
            
        }
    }
    
    
}
